package com.triangle.cashier.adapter;

import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.triangle.cashier.R;

/**
 * 选择商品列表适配器
 * Created by  on 2018/6/30.
 */

public class PendingOrderDetailAdapter extends BaseAdapter {
    public int count = 7;
    private LayoutInflater mInflater;//得到一个LayoutInfalter对象用来导入布局
    private Context context;


    public PendingOrderDetailAdapter(Context context) {
        this.context = context;

        this.mInflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return count;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.pending_order_detail_item, null);
            holder = new ViewHolder();
            holder.indexTextView = convertView.findViewById(R.id.index_TV);
            holder.numTextView = convertView.findViewById(R.id.num_TV);
            holder.nameTextView = convertView.findViewById(R.id.name_TV);
            holder.countTextView = convertView.findViewById(R.id.count_TV);
            holder.priceTextView = convertView.findViewById(R.id.priceTV);
            holder.totalTextView = convertView.findViewById(R.id.total_TV);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (position % 2 == 1) {
            convertView.setBackgroundColor(context.getColor(R.color.selected_goods_odd_line_bg));
        } else {
            convertView.setBackgroundColor(context.getColor(R.color.selected_goods_even_line_bg));
        }
        holder.indexTextView.setText((position + 1) + "");


        return convertView;
    }


    public interface OnChangeOnListener {
        void refresh();
    }

    /**
     * 存放控件
     */
    private final class ViewHolder {
        TextView indexTextView;//序号
        TextView numTextView;// 货号
        TextView nameTextView;//商品名称
        TextView countTextView;//数量
        TextView priceTextView;//价格
        TextView totalTextView;// 小计


    }


}
